package socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {

	public static void main(String[] args) throws UnknownHostException, IOException {
		// 指定服务器的地址端口，返回Socket
		Socket client = new Socket("127.0.0.1", 8080);
		System.out.println("我是客户端。。。");
		// 获取输出流
		OutputStream os = client.getOutputStream();
		PrintWriter pw = new PrintWriter(os);
		pw.write("用户名：bo'b;密码：123");
		pw.flush();
		client.shutdownOutput();

		// 获取输入流，并读取客户端信息
		InputStream is = client.getInputStream();
		InputStreamReader isr = new InputStreamReader(is);
		BufferedReader br = new BufferedReader(isr);
		StringBuilder sb = new StringBuilder();
		String line = null;

		while ((line = br.readLine()) != null) {
			sb.append(line);
		}
		System.out.println(sb.toString());
		client.shutdownInput();
		// 关闭资源
		br.close();
		isr.close();
		is.close();
		pw.close();
		os.close();
		client.close();

	}
}
